home *** CD-ROM | disk | FTP | other *** search
- Path: utpapa.ph.utexas.edu!read
- From: read@utpapa.ph.utexas.edu (Dave Read)
- Newsgroups: comp.lang.c++
- Subject: How does iomanip.h work?
- Date: 24 Mar 1996 18:09:29 GMT
- Organization: Physics Department, University of Texas at Austin
- Message-ID: <4j434p$2nm@geraldo.cc.utexas.edu>
- NNTP-Posting-Host: utpapa.ph.utexas.edu
-
-
- I want to derive a class from ostream and have it do some special
- formatting for me. I'd like to control the formatting code of
- my class the same way you control the formats of other streams with
- the code in iomanip.h. For example, I'd like to do
- mystream << set_my_option(5) << "This is some output." << endl;
-
- The problem is, I can't for the life of me figure out how the code in
- Borland's iomanip.h does its thing! Can anyone explain to me how this
- stuff works? For reference, I have included a small segment of the
- code from iomanip.h (just enough to see how they do setw() ).
-
- I would be extremely grateful for uded a small segment of the
- code from iomanip.h (just enough to see how they do setw() ).
-
- I would be extremely grateful for any light shed!
-
- Thanks,
- Dave
-
- --
-
- template<class typ> class _EXPCLASS smanip {
- ios _FAR & (_RTLENTRY *_fn)(ios _FAR &, typ);
- typ _ag;
- public:
- _RTLENTRY smanip(ios _FAR & (_RTLENTRY *_f)(ios _FAR &, typ), typ _a) :
- _fn(_f), _ag(_a) { }
- friend istream _FAR & _RTLENTRY operator>>(istream _FAR & _s,
- smanip<typ> _FAR & _f) {
- (*_f._fn)(_s, _f._ag); return _s; }
- friend ostream _FAR & _RTLENTRY operator<<(ostream _FAR & _s,
- smanip<typ> _FAR & _f) {
- (*_f._fn)(_s, _f._ag); return _s; }
- };
-
-
- // set the field width to n
-
- smanip<int> _RTLENTRY _EXPFUNC setw(int _n);
-
-
- --
- Dave Read, Ph.D. (read@physics.utexas.edu) "When in doubt, sheet it out."
- UT-Austin Heavy Ion Physicist
- PDGA #9821 G O B R A V E S ! !
-